package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.controls.Alert;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.UpdateBasicInventionEvent;
	import net.optix.ip.model.ModelLocator;

	public class UpdateBasicInventionCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();

	
		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:UpdateBasicInventionEvent = UpdateBasicInventionEvent( event );
			
			var delegate:UpdateBasicInventionDelegate = new UpdateBasicInventionDelegate( this );     
			delegate.updateInvention( myEvent.vo );
			

		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{		
			trace(event.result);
			var title:String	=	"Result of update invention ";
			var message:String;
			
			try
			{
				var invention:XML			=	event.result;
				//trace(invention);
				var	result:int				=	invention.result;
				switch(result)
				{
					case -2:
						model.result	=	"Access Denied !";
						break;
					case -1:
						model.result	=	"The invention can't be editing now , may it is already be published !";
						break;
					case 0:
						model.result	=	"Program error!";
						break;
					case 1:
						model.result	=	"Successfully update the invention!";
						
						break;
				}
			}
			catch(error:Error)
			{
				message	=	"Program error";
			}
			
			model.bSubmit	=	true;
			
			
			
			
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			
			model.result	=	"Program error";
			
		}

	}
}